@extends('layout.admin.index')

@section('content')
<style>
	  .inputPic{ cursor:pointer;opacity:0;ilter:alpha(opacity=0);width:100%;height:100%;position: absolute;top: 0;left: 51;z-index: 9;}
</style>
	<div class="panel admin-panel">
	<div class="panel-head" id="add"><strong><span class="icon-pencil-square-o"></span>增加内容</strong></div>
	  	<div class="body-content">
		    <form method="post" class="form-x" action="/admin/datalist/doadd" enctype="multipart/form-data">  
		      	{{ csrf_field() }}
		      	<div class="form-group">
			        <div class="label">
			          <label>产品型号：</label>
			        </div>
		        <div class="field">
			          <select name="goods_model" class="input w50 nosele">
			          		@foreach($data as $key=>$value)
			                <option value="{{ $value['id'] }}" @if(!empty(session('newid')) && session('newid') == $value['id']) selected @endif>{{ $value['goods_model'] }}</option>
			                @endforeach
			            </select>
			          <div class="tips"></div>
			          <div class="tipss">未设置商品详情的,不在前台显示</div>
		        </div>
		      	</div>
		      	<div class="form-group">
			        <div class="label">
			          <label>图片：</label>
			        </div>
			        <div class="field">
				        
				        <input type="file" onchange="info(this,'#picinfo1')" class="button bg-blue margin-left inputPic" style="float:left;" name="pic1">
				       	<div style="float:left;"><img src="/web/images/public.png" id="picinfo1" width="51" height="51" style="border:2px solid red;"></div>
				       	<input type="file" onchange="info(this,'#picinfo2')" class="button bg-blue margin-left inputPic" style="float:left;" name="pic2">
				       	<div style="float:left;"><img src="/web/images/public.png" id="picinfo2" width="51" height="51"></div>
				       	<input type="file" onchange="info(this,'#picinfo3')" class="button bg-blue margin-left inputPic" style="float:left;" name="pic3">
				       	<div style="float:left;"><img src="/web/images/public.png" id="picinfo3" width="51" height="51"></div>
				       	<input type="file" onchange="info(this,'#picinfo4')" class="button bg-blue margin-left inputPic" style="float:left;" name="pic4">
				       	<div style="float:left;"><img src="/web/images/public.png" id="picinfo4" width="51" height="51"></div>
				       	<div class="tipss">图片尺寸：1500*1500</div>
			        </div>
			    </div>
			        <br><br><br><br>
			       
		      
		      <if condition="$iscid eq 1">
		        <div class="form-group">
			        <div class="label">
			        	<label>所属分类：</label>
			        </div>
		          	<div class="field">
		          		
			            <select name="goods_sort" class="input w50 nosele">
			            <option value="0">请选择分类</option>
			            @foreach($goods_cate as $k=>$v)
			              
			              
			              <option value="{{ $v['id'] }}">{{ $v['goods_name'] }}</option>
			             @endforeach
			            </select>

			            <div class="tips"></div>
		          	</div>
		        </div>
		        <div class="form-group">
		            <div class="label">
		            	<label>其他属性：</label>
		            </div>
		            <div class="field" style="padding-top:8px;"> 
			            精品推荐 <input id="isvouch"  type="checkbox" name="goods_boutique" value="2"/>
			            置顶 <input id="istop"  type="checkbox" name="goods_stick" value="2"/> 
		          	</div>
		        </div>

				<!-- 商品标题 -->
				<!-- 设置商品库存 -->
				<div class="form-group">
		            <div class="label">
		            	<label>商品标题</label>
		            </div>
		            <div class="field" style="padding-top:8px;"> 
			            <textarea name="goods_title" style="width:241px;height:142px;resize:none;"></textarea> 
		          	</div>
		        </div>
				<!-- 设置商品库存结束 -->

				<!-- 商品标题结束 -->
				
				<!-- 选择cpu配置 -->
		        <if condition="$iscid eq 1">
				
		        <div class="form-group a" id="jilianContainer">
			        <div class="label">
			        	<label>cpu:</label>
			        </div>
		          	<div class="field">
			            <select name="sele[]" class="input w50 cpu">
			                <option value="1">请选择</option>
			                <option value="25">CPU</option>
			               
			            </select>
			            <div class="tips"></div>
			            <div class="tips"></div>
		        	</div>

				</div>
		        </if>
		        <!-- 结束CPU配置 -->

		        <!-- 选择内存配置 -->
		        <div class="form-group">
		        </div>
				<if condition="$iscid eq 1">
				
		        <div class="form-group">
			        <div class="label">
			        	<label>内存：</label>
			        </div>
		          	<div class="field">
			            <select name="sele[]" class="input w50 sele">
			               <option value="1">请选择</option>
			               <option value="26">内存</option>
			            </select>
			            <div class="tips"></div>
		        	</div>
				</div>
		        </if>
				<!-- 选择硬盘配置结束 -->
				<br>

				<!-- 选择显卡配置 -->
		        <if condition="$iscid eq 1">
		        

		        <br>
				<!-- 选择硬盘配置 -->
				<if condition="$iscid eq 1">
				
		        <div class="form-group">
			        <div class="label">
			        	<label>硬盘：</label>
			        </div>
		          	<div class="field">
			            <select name="sele[]" class="input w50 sele">
			                <option value="1">请选择</option>
			                <option value="35">硬盘</option>
			            </select>
			            <div class="tips"></div>
		        	</div>
				</div>
		        </if>
				<!-- 选择硬盘配置结束 -->
				<br>

				<!-- 选择主板配置 -->
				
				<if condition="$iscid eq 1">
				
		        <div class="form-group">
			        <div class="label">
			        	<label>主板：</label>
			        </div>
		          	<div class="field">
			            <select name="sele[]" class="input w50 sele">
			                <option value="1">请选择</option>
			               <option value="28">主板</option>
			            </select>
			            <div class="tips"></div>
		        	</div>
				</div>
		        </if>
				<!-- 选择主板配置结束 -->
				<br>
				<!-- 其他配置 -->
				<div class="form-group">
		            <div class="label">
		            	<label>其他配置：</label>
		            </div>
		            <div class="field" style="padding-top:8px;"> 
			            系统 <input id="ishome"  type="text" name="goods_config_other_system" />
			            电池 <input id="isvouch"  type="text" name="goods_config_other_battery" value="无"/>
			            前摄像头 <input id="istop"  type="text" name="goods_config_other_camera_f" value="无"/> 
			            后摄像头 <input id="istop"  type="text" name="goods_config_other_camera_b" value="无"/> 
		          	</div>
		          	<div class="field" style="padding-top:8px;"> 
		          	指纹识别: <input type="radio" name="goods_config_other_finger" value="1">前置识别
			            	  <input type="radio" name="goods_config_other_finger" value="2">后置识别
			            	  <input type="radio" name="goods_config_other_finger" value="3" checked>不支持
		    
		        	</div>
		        </div>
				<!-- 其他配置结束 -->

				<!-- 设置商品库存 -->
				<div class="form-group">
		            <div class="label">
		            	<label>库存</label>
		            </div>
		            <div class="field" style="padding-top:8px;"> 
			            <input type="text" name="goods_inventory" value="">
		          	</div>
		        </div>
				<!-- 设置商品库存结束 -->

				<!-- 设置商品价格 -->
				<div class="form-group">
		            <div class="label">
		            	<label>价格</label>
		            </div>
		            <div class="field" style="padding-top:8px;"> 
			            <input type="text" name="goods_price">
		          	</div>
		        </div>
				<!-- 设置商品价格结束 -->

				<!-- 编辑商品详情 -->

				<!-- 加载编辑器的容器 -->
				<center>
				    <script id="container" name="datalist" type="text/plain" style="width:1100px;height:300px;">
				        
				    </script>
			    </center>
					<!-- 配置文件 -->
				    <script type="text/javascript" src="/ueditor/ueditor.config.js"></script>
				    <!-- 编辑器源码文件 -->
				    <script type="text/javascript" src="/ueditor/ueditor.all.js"></script>
				    <!-- 实例化编辑器 -->
				    <script type="text/javascript">
				        var ue = UE.getEditor('container');
				    </script>
			    
				<!-- 编辑商品详情结束 -->
				<br>

		      	<div class="form-group">
			        <div class="label">
			            <label></label>
			        </div>
			        <div class="field">
			            <button class="button bg-main icon-check-square-o" type="submit"> 提交</button>
			        </div>
		      	</div>
		    </form>
		</div>
</div>	

<script>


// 当改变下拉表单时调用ajax函数
nosele = null;
$('.nosele').change(function(){
	nosele = 1;
})
$('.nosele').blur(function (){
	nosele = null;
})

$('select').change(ajax);

	
	function ajax(){
		if(nosele == 1){
			return false;
		}
		// 初始化清除下拉菜单自定义的类
		$('select').removeClass('as');
		// 获取当前选择下拉菜单的value值
		var l = $(this).val();
		// 拼接一个类路径
		var a = 'a'+l;
		// 给当前下拉菜单添加一个as类
		$(this).addClass('as');

		
		// alert(l);
		// 发送ajax请求
		$.ajax({
			type:"GET",
			url:"/admin/datalist/ajax?id="+l,
			dataType:"json",
			success: function(msg){
				// 在当前下拉列表后追加一个下拉列表
				$('.as').after('<select class="'+a+' input w50" name="sele[]"><option value="1">请选择</option></select>');
				console.log(msg);
				if(msg.length  == 0) {
					// 如果ajax返回一个空数组则移除下拉列表后的下拉列表
					$('.as').nextAll().remove();
					
					return false;
				}
				$.each(msg,function(k,v){
					// 向下拉列表中追加数据
					$("<option value='"+v.id+"'>"+v.goods_config_cate+"</option>").appendTo('.'+a);
					$('.as').removeClass('as');
				})
				$('.'+a+'').change(ajax);
						
					},
			
			async:"false"
		})
}


      
          /**
           * 无刷新头像
           * 
           * @param       object          file          获取file所有属性
           * @param       object          reader        读取文件属性
           * @param       int             file.files[0]['size']  获取上传文件大小
           * @param       string          file.files[0]['type']
           * @将文件的路径赋予img src属性
           */
          // 获取input属性
          function info(file,a){
          	console.log(file.files[0]);
          	console.log(a)
            // 判断是否获取成功
            if(file.files && file.files[0]){
         		
                  var reader = new FileReader();
                  // 将每次读取的路径赋予img src
                  reader.onload = function(evt){  
                     $(a).attr('src',evt.target.result)
                  };
                   reader.readAsDataURL(file.files[0]);
                   
            }
          }



          
     

</script>




@endsection